package cn.iot.controller.sys;

import cn.iot.common.dto.ResultMsg;
import cn.iot.sys.entity.SysClass;
import cn.iot.sys.service.SysClassService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/sys/class")
public class SysClassController {
    @Autowired
    private SysClassService sysClassService;
    private Logger logger = LoggerFactory.getLogger(getClass());

    @PreAuthorize("@ss.hasPermi('system:class:list')")
    @PostMapping("/getSysClassList")
    public ResultMsg getSysClassList(@RequestParam Map<String, Object> params){
        logger.info("SysClassController getSysClassList params{}",params);
        ResultMsg msg = sysClassService.getSysClassList(params);
        logger.debug("SysClassController getSysClassList msg{}",msg);
        return msg;
    }

    @PostMapping("addSysClass")
    public ResultMsg addSysClass(@RequestBody SysClass sysClass){
        logger.info("SysClassController addSysClass sysClass{}",sysClass);
        ResultMsg msg = sysClassService.addSysClass(sysClass);
        logger.debug("SysClassController addSysClass msg{}",msg);
        return msg;
    }

    @PostMapping("delSysClassById")
    public ResultMsg delSysClassById(@RequestParam int id){
        logger.info("SysClassController delSysClassById id{}",id);
        ResultMsg msg = sysClassService.delSysClassById(id);
        logger.debug("SysClassController delSysClassById msg{}",msg);
        return msg;
    }
    @PostMapping("getSysClass")
    public ResultMsg getSysClass(){
        logger.info("SysClassController getSysClass start ...");
        ResultMsg msg = sysClassService.getSysClass();
        logger.debug("SysClassController getSysClass msg{}",msg);
        return msg;
    }
    @PostMapping("viewSysClassById")
    public ResultMsg viewSysClassById(@RequestParam int id){
        logger.info("SysClassController viewSysClassById id{}",id);
        ResultMsg msg = sysClassService.viewSysClassById(id);
        logger.debug("SysClassController viewSysClassById msg{}",msg);
        return msg;
    }
    @PostMapping("updClass")
    public ResultMsg updClassById(@RequestBody SysClass sysClass){
        logger.info("SysClassController updClassById sysClass{}",sysClass);
        ResultMsg msg = sysClassService.updSysClassById(sysClass);
        logger.debug("SysClassController updClassById msg{}",msg);
        return msg;
    }

    @PostMapping("updStatus")
    public ResultMsg updStatus(@RequestBody SysClass sysClass){
        logger.info("SysClassController updStatus sysClass{}",sysClass);
        ResultMsg msg = sysClassService.updStatusById(sysClass);
        logger.debug("SysClassController updStatus msg{}",msg);
        return msg;
    }

    @PostMapping("getClassByName")
    public ResultMsg getClassByName(@RequestParam String name){
        logger.info("SysClassController getClassByName name{}",name);
        ResultMsg msg = sysClassService.getClassByName(name);
        logger.debug("SysClassController getClassByName msg{}",msg);
        return msg;
    }

    @RequestMapping("/uploadClassInfo")
    public ResultMsg uploadClassInfo(@RequestParam("file") MultipartFile file) {
        logger.info("SysClassController uploadClassInfo file{}",file);
        ResultMsg msg = sysClassService.uploadClassInfo(file);
        logger.debug("SysClassController uploadClassInfo msg{}",msg);
        return msg;
    }
}
